#!/usr/bin/php
<?php
$last = time();
$dir = dirname(__FILE__);
$files = array('prednasky', 'prednasky2', 'definitor');
while(true) {
    clearstatcache();
    foreach ($files as $f) {
        if (max(filectime("$dir/$f.tex"), filemtime("$dir/$f.tex")) > $last) {
            exec("pdflatex $dir/$f.tex </dev/null", $output);
            unlink("$dir/$f.log");
            unlink("$dir/$f.aux");
            echo "PDF of $f.tex built at " . date("H:i:s") . "\n";
            $last = time();
        }
    }
    sleep(1);
}
